//
//  WYSearchBar.m
//  WYModel
//
//  Created by ios on 2017/3/6.
//  Copyright © 2017年 Wy. All rights reserved.
//

#import "WYSearchBar.h"

@interface WYSearchBar ()

@property(nonatomic,strong)UITextField *searchBarTextField;
@property(nonatomic,strong)UIImageView *searchImage;


@end

@implementation WYSearchBar

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self == [super initWithFrame:frame]) {
        [self setUpSubviews];
    }
    return self;
}


-(void)setUpSubviews{
   
    [self addSubview:self.searchBarTextField];
}


-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat searchBarTextFieldX = 0;
    CGFloat searchBarTextFieldY = 5;
    CGFloat searchBarTextFieldW = self.frame.size.width;
    CGFloat searchBarTextFieldH = 25;
    self.searchBarTextField.frame = CGRectMake(searchBarTextFieldX, searchBarTextFieldY, searchBarTextFieldW, searchBarTextFieldH);
}

-(UITextField *)searchBarTextField{
    if (!_searchBarTextField) {
        _searchBarTextField                   = [UITextField new];
        _searchBarTextField.backgroundColor   = [UIColor whiteColor];
        _searchBarTextField.layer.borderColor = [UIColor colorWithHexString:@"#dddddd"].CGColor;
        _searchBarTextField.layer.cornerRadius  = 5;
        _searchBarTextField.layer.borderWidth   = 0.5;
        _searchBarTextField.layer.masksToBounds = YES;
        _searchBarTextField.placeholder         = @"搜索其他";
        _searchBarTextField.leftView            = self.searchImage;
        _searchBarTextField.leftViewMode        = UITextFieldViewModeAlways;
        
      //  [_searchBarTextField setValue:[UIColor colorWithHexString:@"#999999"] forKey:@"placeholderLabel.textColor"];
        
    }
    return _searchBarTextField;
}


-(UIImageView *)searchImage{
    if (!_searchImage) {
        _searchImage           = [UIImageView new];
        _searchImage.image     = [UIImage imageNamed:@"fa-search"];
        _searchImage.frame     = CGRectMake(0, 0, 20, 20);
        _searchImage.contentMode = UIViewContentModeCenter;
    }
    return _searchImage;
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
